package com.banshuibao.bsb_android.activity;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;

import com.banshuibao.bsb_android.Constants;
import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.adapter.MenuTagAdapter;
import com.banshuibao.bsb_android.http.HttpResponse;
import com.banshuibao.bsb_android.http.HttpUtil;
import com.banshuibao.bsb_android.model.ExpertTreeModel;
import com.banshuibao.bsb_android.util.IntentManager;
import com.banshuibao.bsb_android.view.FlowLayoutManager;

import java.util.List;

public class MenuTagActivity extends BaseActivity implements MenuTagAdapter.TagItemOnClickListener {

    RecyclerView recyclerView;
    private List<ExpertTreeModel.DataBean.ChildrenBean> tradeList;
    private List<ExpertTreeModel.DataBean.ChildrenBean> taxList;
    private List<ExpertTreeModel.DataBean.ChildrenBean> topicList;
    private String tag;
    MenuTagAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tag);
        tag = getIntent().getStringExtra("tag");
        initView();
        setData();
    }

    public void initView() {

        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new FlowLayoutManager());
        adapter = new MenuTagAdapter(this);
        recyclerView.setAdapter(adapter);
        adapter.setTagItemOnClickListener(this);

    }


    public void setData() {
        /**
         * 行业税种专题数据
         */
        HttpUtil.doPost(Constants.Url.EXPERT_TREE, null, new HttpResponse(this, ExpertTreeModel.class) {
            @Override
            public void onResult(Object obj) {
                ExpertTreeModel expertTreeModel = (ExpertTreeModel) obj;
                List<ExpertTreeModel.DataBean> data = expertTreeModel.getData();
                for (int i = 0; i < data.size(); i++) {
                    if (data.get(i).getName().equals("行业")) {
                        tradeList = data.get(i).getChildren();
                    } else if (data.get(i).getName().equals("税种")) {
                        taxList = data.get(i).getChildren();
                    } else if (data.get(i).getName().equals("专题")) {
                        topicList = data.get(i).getChildren();
                    }
                }
                switch (tag) {
                    case "trade":
                        setTitleText("行业");
                        if (tradeList != null) {
                            adapter.setData(tradeList);
                        }
                        break;
                    case "tax":
                        setTitleText("税种");
                        if (taxList != null) {
                            adapter.setData(taxList);
                        }
                        break;
                    case "topic":
                        setTitleText("专题");
                        if (topicList != null) {
                            adapter.setData(topicList);
                        }
                        break;
                }
            }
        });
    }

    @Override
    public void setData(ExpertTreeModel.DataBean.ChildrenBean childrenBean) {
        if (childrenBean != null) {
            IntentManager.goMenuTagResultAcitivty(MenuTagActivity.this,childrenBean.getName(),tag,childrenBean.getUuid());
        }
    }
}
